home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / Extras / SysGen / fromfile < prev    next >
Encoding:
Text File  |  1992-01-26  |  3.4 KB  |  123 lines

  1. \ file? NAME ... prints file that NAME was compiled from...
  2. \
  3. \ NOTE: this only is true if FILEHEADERS was true at compile time...
  4. \       This is the normal default state for JForth.
  5. \ 00001 26-jan-92 mdh  CR chganged to >NEWLINE
  6. include? valid-name? jf:smart-id.
  7.  
  8. decimal
  9.  
  10. \ : @?   ( addr -- )  dup 1 and
  11. \   IF   cr ." long fetch, odd boundary: "  base @ hex swap . base !  quit
  12. \   THEN @ ;
  13. \ : @ @? ;
  14.  
  15. ' forth >name  ' root - constant vocsize
  16.  
  17. : fileheader?  ( nfa -- flag )
  18.   1+ odd@  $ 3a3a3a3a =
  19. ;
  20.  
  21. : unnest  ( -- nfa )
  22.   BEGIN  n>link @   ( prevnfa -- )
  23.          dup fileheader?
  24.   UNTIL  ;
  25.  
  26. : nested?   ( nfa -- true-if-;;; )
  27.   @  $ 833b3b3b =   ;
  28.  
  29.  
  30. : lookforit   ( addr cnt -- , of filename text )
  31.   here pad 128 + $move
  32.   >dos  dosstring 2+  (fopen) -dup       ( wants null-term )
  33.   IF    dup  markfclose  tempfile !
  34.         tempbuff openfv markfreeblock    ( -- )
  35.         BEGIN  2 x>r  ?pause  2 xr>
  36.                tempfile @  tempbuff  pad 128 readline    
  37.                ( pad actual-line-len ) dup  0< 0=
  38.         WHILE  ( not end of file ) ( pad actual-line-len ) dup
  39.                IF  ( not an empty line )   ( pad len -- )
  40.                    2dup pad 128 + count match?  ( pad len flag -- )
  41.                    IF   ( found it there! ) cr
  42.                         BEGIN  type  2 x>r  ?pause 2 xr>   cr  ( -- )
  43.                                tempfile @ tempbuff
  44.                                pad 128 readline dup 0= over 0< or
  45.                         UNTIL  ( adr cnt -- )
  46.                    THEN
  47.                THEN 2drop
  48.         REPEAT 2drop
  49.         tempbuff @ unmarkfreeblock
  50.         tempbuff closefvread
  51.         tempfile @ dup unmarkfclose  fclose
  52.   ELSE  cr ." Sorry, can't open the file."
  53.   THEN  ;
  54.  
  55. user #nested
  56.  
  57. : nextname?   ( nfa -- next-nfa OR 0 )  dup 0> >r
  58.   BEGIN  2- dup r@
  59.          IF
  60.             0>
  61.          ELSE
  62.             >abs
  63.          THEN
  64.          IF   dup valid-name?
  65.          ELSE drop false true
  66.          THEN
  67.   UNTIL  rdrop  ;
  68.  
  69.  
  70. : NFA.FILE? ( nfa -- , file? with this NFA )
  71.        1 #nested !
  72.        >newline dup id. 
  73.        BEGIN  dup nextname? ( thisnfa prevnfa/0 -- ) -dup
  74.               IF   swap drop dup nested?
  75.                    IF    1 #nested +!
  76.                    THEN
  77.                    dup fileheader?  dup
  78.                    IF   -1  #nested +!
  79.                    THEN #nested @ 0= and
  80.               ELSE cr ." FILE?: fileheaders not found!" quit
  81.               THEN
  82.        UNTIL
  83.        ."  was compiled from "  dup >r
  84.        ( nfa -- )  dup c@ $ 1f and    ( nfa cnt -- )
  85.        4 -  ( nfa cnt-4 -- ) ( adjust out the locater text )
  86.        swap 5 + swap  ( adr cnt -- , of filename )
  87.        2dup type  cr   r> [ ' ::::keyboard >name ] literal = 0=
  88.        IF   ." Display?" y/n
  89.             IF   2dup lookforit
  90.             THEN
  91.        THEN 2drop
  92. ;
  93. \
  94. : file?   ( -- )   ( eats: name )
  95.   >newline bl word  find  cr
  96.   IF   ( pfa -- )  >name ( -- nfa)
  97.       nfa.file?
  98.   ELSE $type ."  isn't in the selected vocabularies."
  99.   THEN  cr ;
  100.  
  101. \ : view   ( -- , eats filename from input )
  102. \   file?  ;
  103.  
  104.  
  105. : MATCH.FILE? ( nfa -- , file? if match )
  106.     dup count $ 1F and ( -- nfa addr count )
  107.     here count 2 pick = ( nfa addr count here )
  108.     IF  text=? ( -- nfa flag )
  109.         IF nfa.file? cr
  110.         ELSE drop
  111.         THEN
  112.     ELSE 2drop 2drop
  113.     THEN
  114. ;
  115.  
  116. : EACH.FILE?  ( <name> -- , file? for every entry in dict. )
  117.     bl word drop
  118.     ' match.file? is when-scanned
  119.     ' drop is when-voc-scanned
  120.     scan-all-vocs
  121. ;
  122.